// ForceAssignCommand.cpp: implementation of the ForceAssignCommand class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ForceAssignCommand.h"
#include "ForceAssign.h"
#include "part.h"
#include "FunctionRegister.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

ForceAssignCommand::ForceAssignCommand(JointFunction* pSufferPort)
{
	ASSERT(pSufferPort);
	m_pSufferPort = pSufferPort;
}

ForceAssignCommand::~ForceAssignCommand()
{

}

BOOL ForceAssignCommand::Execute()
{
	FunctionObject* pFunction = m_pSufferPort->GetOwner()->GetFunction(
		FunctionObject::eFORCEASSIGN);

	if(pFunction == NULL)
	{
		FunctionRegisterInfo* pInfo = GetFunctionRegister().Get(FunctionObject::eFORCEASSIGN);
		pFunction = pInfo->CreateObject();
		pFunction->SetOwner(m_pSufferPort->GetOwner());
		m_pSufferPort->GetOwner()->AttachFunction(pFunction);
	}
	ASSERT(pFunction);
	ASSERT(pFunction->GetRuntimeClass() == RUNTIME_CLASS_EX(ForceAssign));
	
	static_cast<ForceAssign*>(pFunction)->SufferForcePort(m_pSufferPort);
	
	return pFunction->Execute();
}